// TOWN SCRIPT
//    Town 5

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

int i;

body;

beginstate INIT_STATE;
if(get_flag(5,0) == 0) {
		message_dialog("As you enter this cavern, you stop. Before you is a small Avernite settlement. It's too far away for you to see through the town gates, but if you could get there, you'd be able to rest.","Between the town's thick stone walls and you, however, is a wide river. Fortunately, a small bridge spans it. You might finally be able to get to safety...");
		set_flag(5,0,1);
		}
// Called upon entering
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.
break;


//Stop them going back to previous town
beginstate 10;
	message_dialog("You've already explored that section of the caves; heading back there instead of pressing on doesn't make any sense.","");
	block_entry(1);
break;

//Halfway to bridge
beginstate 11;
	if(get_flag(5,0) == 0) {
		message_dialog("As you are crossing this cavern, you stop. Before you is a small Avernite settlement - you can see people milling about, going about their business without a care in the world, and guards, alert for any beasts lurking in the caves.","Between the town's thick stone walls and you, however, is a wide river. Fortunately, a small bridge spans it. You might finally be able to get to safety...");
		set_flag(5,0,1);
	}
break;

//Bridge
beginstate 12;
	if(get_flag(5,1) == 0) {
		message_dialog("You step onto the stone bridge - it looks old, but after carefully testing your weight on it you discover it is more than capable of ferrying you to the other side.","");
		set_flag(5,1,1);
	}
break;


//BEAST!!
beginstate 13;
	if(get_flag(5,2) == 0) {
		message_dialog("Suddenly you see a flash of red from in front of you - a monster like the one you fought earlier must have gotten ahead of you somehow, and now it's blocking the only way to safety.","You shout for help, but the town is too far away to hear you. You're going to have to defeat it yourself...");
		set_flag(5,2,1);
		activate_hidden_group(1);
	}
break;

//Move to town
beginstate 14;
	if(get_flag(5,3) == 0) {
		message_dialog("You try to flee from the beast, but it snarls and leaps forward to strike you. You mange to evade it's blow, but you won't be able to leave whilst it's still here.","");
		block_entry(1);
	} else {
		message_dialog("As you reach the far end of the river, exhausted from your battle with the beast, you see several soldiers running towards you - they must have heard the beasts' roar, and came as soon as they could.","They help you into the fort, keeping an eye out for any more attacks. You're safe, at last. THE END.");
		
		change_spell_level(0,0,1,(1 * get_flag(250,0)));
		change_spell_level(1,0,1,(1 * get_flag(250,1)));
		change_spell_level(2,0,1,(1 * get_flag(250,2)));
		change_spell_level(3,0,1,(1 * get_flag(250,3)));
	
	
	end_scenario(1);
}
break;